﻿using System.Runtime.Serialization;
using Microsoft.Commerce.Contracts;
using System;

namespace MusicWorks.Service.DataContracts
{
    public class Product : HierarchicalCatalogEntity
    {
        /// <summary>
        /// defines the model name for this commerce entity
        /// </summary>
        public new const string ModelNameDefinition = "Product";

        public Product() : base(ModelNameDefinition) { }
        public Product(string modelNameDefinition) : base(modelNameDefinition) { }
        public Product(CommerceEntity commerceEntity) : base(commerceEntity) { }

        [DataMember]
        public string DisplayName
        {
            get { return _commerceEntity.GetPropertyValue("DisplayName") as string; }
            set { _commerceEntity.SetPropertyValue("DisplayName", value); }
        }
        [DataMember]
        public decimal ListPrice
        {
            get { return Convert.ToDecimal(CommerceEntity.GetPropertyValue("ListPrice")); }
            set { CommerceEntity.SetPropertyValue("ListPrice", value); }
        }
        [DataMember]
        public string DefinitionName
        {
            get { return CommerceEntity.GetPropertyValue("DefinitionName") as string; }
            set { CommerceEntity.SetPropertyValue("DefinitionName", value); }
        }
        [DataMember]
        public bool UseCategoryPricing
        {
            get { return Convert.ToBoolean(CommerceEntity.GetPropertyValue("UseCategoryPricing")); }
            set { CommerceEntity.SetPropertyValue("UseCategoryPricing", value); }
        }
        [DataMember]
        public string InventoryCondition
        {
            get { return CommerceEntity.GetPropertyValue("InventoryCondition") as string; }
            set { CommerceEntity.SetPropertyValue("InventoryCondition", value); }
        }
        [DataMember]
        public string Description
        {
            get { return CommerceEntity.GetPropertyValue("Description") as string; }
            set { CommerceEntity.SetPropertyValue("Description", value); }
        }

        public static implicit operator Product(CommerceEntity commerceEntity)
        {
            return new Product(commerceEntity);
        }

        #region Nested type: RelationshipName

        public new class RelationshipName : HierarchicalCatalogEntity.RelationshipName
        {
            /// <summary>
            /// The name of the InventoryItems relationship.
            /// </summary>
            public const string InventoryItems = "InventoryItems";


            /// <summary>
            /// The name of the PricingCategory relationship.
            /// </summary>
            public const string PricingCategory = "PricingCategory";

            /// <summary>
            /// The name of the Variants relationship.
            /// </summary>
            public const string Variants = "Variants";
        }

        #endregion
    }
}